package com.questionnaires.model;

import org.hibernate.validator.constraints.NotBlank;

import javax.persistence.*;

/**
 * The user entity class.
 *
 * @author ioana.ruca@gmail.com
 */
@Entity
@Table(name = "USERS")
public class User {

    private long id;
    @NotBlank
    private String firstName;
    @NotBlank
    private String lastName;

    private String username;

    private String password;

    private UserRole role;

    public User() {

    }

    @Id
    @GeneratedValue
    @Column(name = "ID")
    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Column(name = "first_name", nullable = false)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "last_name", nullable = false)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Column(name = "username", nullable = false)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "password", nullable = false)
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Enumerated(EnumType.STRING)
    public UserRole getRole() {
        return role;
    }

    public void setRole(UserRole role) {
        this.role = role;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        User user = (User) o;

        if (id != user.id) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return (int) (id ^ (id >>> 32));
    }

    @Override
  public String toString() {
    return "User{" +
      "firstName='" + firstName + '\'' +
      ", lastName='" + lastName + '\'' +
      ", username='" + username + '\'' +
      ", password='" + password + '\'' +
      ", role=" + role +
      '}';
  }
    
  public boolean checkUserAdmin() {
      
      return UserRole.ADMINISTRATOR.equals(role);
  } 
    
  public boolean checkUserManager() {
      
      return UserRole.MANAGER.equals(role);
  } 
}
